<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>View All Invoice</title>
    </h:head>
    <h:form id="formMain">
        <p:growl id="notif" showDetail="true"/>  
                    <p:poll interval="5"   
                            actionListener="#{MessageManagedBean.checkNewMessage}" immediate="true" update="notif" />
        <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
            <f:view beforePhase="#{InvoiceManagedBean.initView}">
                <h:body>
                    <!-- IDLE DIALOG for -->
                    <p:confirmDialog message="You have been idle for 5 minutes. Do you want to continue?"  
                                     showEffect="bounce" hideEffect="explode"  
                                     header="Warning message" severity="alert" widgetVar="confirmation">  
                        <p:commandButton value="Yes" onclick="confirmation.hide()" type="button" /> 
                        <p:commandButton value="No" update="panel" oncomplete="confirmation.hide()"  
                                         actionListener="#{UserManagedBean.doLogout}" /> 
                    </p:confirmDialog>
                    <div id="header">
                        <h:graphicImage value="../image/newHeader.jpg"/>
                    </div>

                    <div id="content">
                        <table>
                            <tr>  
                                <td style="vertical-align:top">
                                    <p:toolbar style="font-size:80%;height:33px;width:207px"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome="FinanceDeptWorkspace"/>
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>
                                            <p:button title="Mail" outcome="messages" image="ui-icon-mail-closed"/>     
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar>

                                    <p:menu id="menu" style=" width:205px;height: 580px;font-family: Tahoma;border-style: double;font-size: 80%">  
                                        <p:submenu label="Finance Menu">  
                                            <p:menuitem value="Finance Dept Home" url="http://localhost:8080/MerlionERP-war/FRM/FinanceDeptWorkspace.xhtml" ajax="false" icon="ui-icon ui-icon-home"/>  
                                        </p:submenu>
                                        <p:submenu label=" Credit Profiles">
                                            <p:menuitem value="Add New Credit Profile" url="http://localhost:8080/MerlionERP-war/FRM/addCreditProfile.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>  
                                            <p:menuitem value="View Credit Profiles" url="http://localhost:8080/MerlionERP-war/FRM/viewCreditProfile.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="Perform Credit Check" url="http://localhost:8080/MerlionERP-war/FRM/CreditCheck.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label=" Invoices">
                                            <p:menuitem value="Add New Invoice" url="http://localhost:8080/MerlionERP-war/FRM/addInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-document" />
                                            <p:menuitem value="View All Invoices" url="http://localhost:8080/MerlionERP-war/FRM/viewInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="View Outstanding Invoices" url="http://localhost:8080/MerlionERP-war/FRM/viewOutstandingInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="View Overdue Invoices" url="http://localhost:8080/MerlionERP-war/FRM/viewOverdueInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label="Refund">
                                            <p:menuitem value="View Pending Refunds" url="http://localhost:8080/MerlionERP-war/FRM/ViewRefundEntity.xhtml"   ajax="false" icon="ui-icon ui-icon-document" />
                                        </p:submenu>
                                        <p:submenu label="Payment">
                                            <p:menuitem value="Perform Customer Payment" url="http://localhost:8080/MerlionERP-war/FRM/PerformPayment.xhtml"   ajax="false" icon="ui-icon ui-icon-cart" />
                                            <p:menuitem value="View Payment History" url="http://localhost:8080/MerlionERP-war/FRM/ViewCustomerPaymentJournal.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />

                                        </p:submenu>
                                    </p:menu>

                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>
                                <td style=" vertical-align: top">  
                                    <h:graphicImage value="invoice_icon.jpg" style="width:35px;height:35px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Invoices" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>

                                    <p:toolbar style="background-color:  #d9bb73;font-size: 70%;width:1127px"> 
                                        <!-- <p:toolbarGroup align="left" style="text-indent: 300px;font-size: 30px">  
                                             ALL INVOICES
                                         </p:toolbarGroup> -->
                                        <p:divider />
                                        <p:toolbarGroup align="left"> 

                                            <!--<p:commandButton type="push" title="Save" image="ui-icon-disk"/>  -->
                                            <p:commandButton type="push" title="Delete" value="Delete" image="ui-icon-trash" onclick="deleteDialog.show()"/>  
                                            <p:divider />  
                                            <p:button value="New Invoice" outcome="addInvoice" image="ui-icon-plus" />

                                        </p:toolbarGroup>  
                                    </p:toolbar> 

                                    <p:dataTable  id="panel" 
                                                  var="invoices" value="#{InvoiceManagedBean.selectedInvoices}"                       
                                                  paginator="true" rows="5"
                                                  paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                                  rowsPerPageTemplate="5,10,15"  style="font-size:70%;width:1132px;"
                                                  rowEditListener="#{InvoiceManagedBean.onEditRow}"
                                                  selection="#{InvoiceManagedBean.selectedInvoicesArray}"
                                                  emptyMessage="No data found with given criteria" widgetVar="invoiceTable" >  



                                        <f:facet name="header">
                                            <p:outputPanel style="text-align:right"  >
                                                <h:outputText value="Search all fields:" style="margin-left:860px" />  
                                                <p:inputText id="globalFilter" onkeyup="invoiceTable.filter()" style="right:100px;width:150px" />  
                                            </p:outputPanel>
                                        </f:facet>

                                        <p:column style="width: 16px" selectionMode="multiple" />  
                                        <!--VIEW DETAILS-->
                                        <p:column style="width:20px; border-left-color:transparent;border-right-color:transparent">
                                            <f:facet name="header">
                                                <h:outputText value="View"/>
                                            </f:facet>
                                            <p:rowToggler />
                                        </p:column> 
                                        <!--EDIT-->   
                                        <p:column style="width:20px; border-left-color:transparent;border-right-color:transparent">
                                            <f:facet name="header">
                                                <h:outputText value="Edit"/>
                                            </f:facet>
                                            <p:rowEditor  />
                                        </p:column>
                                        <!--DELETE-->
                                        <p:column style="width:20px;border-left-color:transparent;">
                                            <f:facet name="header">
                                                <h:outputText value="Del."/>
                                            </f:facet>
                                            <p:commandButton title="Delete" image="ui-icon ui-icon-trash" ajax="true" immediate="true"
                                                             update="panel" oncomplete="customerdialog.show()">
                                                <f:setPropertyActionListener target="#{InvoiceManagedBean.selectedInvoice}"
                                                                             value="#{invoices}"/>
                                            </p:commandButton>
                                        </p:column>

                                         <p:column>
                                     <p:commandButton image="ui-icon ui-icon-print" value="Invoice" ajax="true" immediate="true"
                                                       actionListener="#{InvoiceManagedBean.generateInvoiceReport}">
                                         <f:setPropertyActionListener target="#{InvoiceManagedBean.selectedViewInvoice}"        
                                                                      value="#{invoices}"/>
                                     </p:commandButton>
                                 </p:column>
                                        
                                        <p:column>
                                     <p:commandButton image="ui-icon ui-icon-print" value="Receipt" ajax="true" immediate="true"
                                                       actionListener="#{InvoiceManagedBean.generateReceiptReport}">
                                         <f:setPropertyActionListener target="#{InvoiceManagedBean.selectedViewInvoice}"        
                                                                      value="#{invoices}"/>
                                     </p:commandButton>
                                 </p:column>
                                        
                                        <p:column sortBy="#{invoices.invoiceId}" 
                                                  filterBy="#{invoices.invoiceId}" 
                                                  filterStyle="width:50px"
                                                  filterMatchMode="contains">  

                                            <f:facet name="header">  
                                                <h:outputText value="Inv. ID" /> 
                                            </f:facet>  
                                            <h:outputText value="#{invoices.invoiceId}" /> 

                                        </p:column> 

                                        <p:column sortBy="#{invoices.salesOrderId}" 
                                                  filterBy="#{invoices.salesOrderId}" 
                                                  filterStyle="width:50px"
                                                  filterMatchMode="contains">  

                                            <f:facet name="header">  
                                                <h:outputText value="SO ID" /> 
                                            </f:facet>  
                                            <h:outputText value="#{invoices.salesOrderId}" /> 

                                        </p:column>  



                                        <p:column style="width: 106px" sortBy="#{invoices.issueDate}" filterBy="#{invoices.issueDate}" filterMatchMode="contains">  
                                            <f:facet name="header">  
                                                <h:outputText value="Issue Date" />  
                                            </f:facet>  
                                            <h:outputText value="#{invoices.issueDate}" >
                                            </h:outputText>
                                        </p:column>

                                        <p:column style="width: 106px" sortBy="#{invoices.invoiceDueDate}" filterBy="#{invoices.invoiceDueDate}" filterMatchMode="contains">  
                                            <f:facet name="header">  
                                                <h:outputText value="Due Date" /> 
                                            </f:facet>   
                                            <h:outputText value="#{invoices.invoiceDueDate}" >
                                            </h:outputText>

                                        </p:column> 


                                        <p:column style="width: 106px" headerText="Discount Rate" 
                                                  sortBy="#{invoices.discountRate}" 
                                                  filterStyle="width:60px"
                                                  filterBy="#{invoices.discountRate}" filterMatchMode="contains">  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{invoices.discountRate}%" >
                                                    </h:outputText>
                                                </f:facet>  
                                                <f:facet name="input">  
                                                    <h:inputText style="width:60px" value="#{invoices.discountRate}" />  
                                                </f:facet>  
                                            </p:cellEditor>
                                        </p:column> 

                                        <p:column style="width: 106px" headerText="Total Price" 
                                                  sortBy="#{invoices.totalPrice}" 
                                                  filterBy="#{invoices.totalPrice}" 
                                                  filterStyle="width:60px"
                                                  filterMatchMode="contains">  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{invoices.totalPrice}" >
                                                        <f:convertNumber type="currency" currencySymbol="S$"/>
                                                    </h:outputText>
                                                </f:facet>  
                                                <f:facet name="input">  
                                                    <h:inputText style="width:50px" value="#{invoices.totalPrice}" />  
                                                </f:facet>  
                                            </p:cellEditor>
                                        </p:column>  


                                        <p:column style="width: 106px" headerText="Status" 
                                                  sortBy="#{invoices.invoiceStatus}" filterBy="#{invoices.invoiceStatus}" 
                                                  filterStyle="width:80px"
                                                  filterMatchMode="contains">  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="Paid" rendered="#{invoices.invoiceStatus}" />
                                                    <h:outputText value="Not Paid" rendered="#{!invoices.invoiceStatus}"/>
                                                </f:facet>  
                                                <f:facet name="input">  
                                                    <h:selectOneMenu value="#{invoices.invoiceStatus}">
                                                        <f:selectItem itemLabel="Paid" itemValue="true" />
                                                        <f:selectItem itemLabel="Not Paid" itemValue="false" />
                                                    </h:selectOneMenu>
                                                </f:facet>  
                                            </p:cellEditor>
                                        </p:column>  


                                        <p:column style="width:20px;border-left-color:transparent;">
                                            <f:facet name="header">
                                                <h:outputText value=""/>
                                            </f:facet>
                                            <p:commandLink title="edit" update="formMain:display1" oncomplete="editDialog.show()">
                                                <p:graphicImage value="about_icon.png" style="width:20px;height:20px"/>
                                                <f:setPropertyActionListener target="#{InvoiceManagedBean.selectedViewInvoice}"
                                                                             value="#{invoices}"/>
                                                <f:setPropertyActionListener value="#{true}" target="#{InvoiceManagedBean.editMode}" />
                                            </p:commandLink>
                                        </p:column>

                                        <p:rowExpansion>  
                                            <h:panelGrid id="expansionRow" columns="3" cellpadding="4" 
                                                         style="border-color:transparent;column-rule-style:hidden">

                                                <h:outputText value="Invoice ID" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{invoices.invoiceId}" />

                                                <h:outputText value="Sales Order ID" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{invoices.salesOrderId}" /> 

                                                <h:outputText value="Amount Due" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="S$ #{invoices.amountDue}" />  

                                                <h:outputText value="Cash In Advance" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="S$ #{invoices.cashInAdvance}" />  

                                                <h:outputText value="Credit Term" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{invoices.creditTerm} days" />  

                                                <h:outputText value="Discounted Credit Term" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{invoices.discountedCreditTerm} days" />  

                                                <h:outputText value="Payment Method" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{invoices.paymentMethod}" /> 
                                               
                                            </h:panelGrid>  
                                        </p:rowExpansion>  

                                    </p:dataTable>  


                                    <!--DIALOG FOR DELETING A  SINGLE ROW-->
                                    <p:confirmDialog message="Are you sure you want to delete this invoice?"  
                                                     showEffect="blind" hideEffect="explode"  
                                                     header="Delete Invoice" severity="alert" widgetVar="customerdialog">  
                                        <p:commandButton value="Yes" update="panel" ajax="true" immediate="true" oncomplete="customerdialog.hide()"  
                                                         actionListener="#{InvoiceManagedBean.doDelete}" />  
                                        <p:commandButton value="No" onclick="customerdialog.hide()" type="button" />   
                                    </p:confirmDialog>

                                    <!--DIALOG FOR DELETING MULTIPLE ROW-->
                                    <p:dialog header="Delete Selected Records" modal="true" widgetVar="deleteDialog">

                                        <h:outputText value="You are about to permanently delete invoice records." /><br /><br />
                                        <h:outputText value="Are you sure you want to continue?" /><br /><br/>

                                        <center>
                                            <p:commandButton value="Yes" ajax="true" immediate="true" update="panel" oncomplete="deleteDialog.hide()" actionListener="#{InvoiceManagedBean.doDeletes}" />
                                            <p:commandButton value="No" onclick="deleteDialog.hide()" /> 

                                        </center>
                                    </p:dialog>


                                    <!--DIALOG FOR VIEW-->
                                    <p:dialog header="Invoice Detail" widgetVar="editDialog" resizable="false"  
                                              width="800" showEffect="explode" hideEffect="explode">  
                                        <center>
                                            <!--   <p:outputPanel id="editDialogOutput"> -->
                                            <h:panelGrid id="display1" columns="3" cellpadding="4">  

                                                <h:outputText value="Invoice ID" />  
                                                <h:outputText value=":" /> 
                                                <h:outputText value=" #{InvoiceManagedBean.selectedViewInvoice.invoiceId}" />  

                                                <h:outputText value="Sales Order ID" />  
                                                <h:outputText value=":" /> 
                                                <h:outputText value=" #{InvoiceManagedBean.selectedViewInvoice.salesOrderId}" />  

                                                <h:outputText value="Cash In Advance" />
                                                <h:outputText value=":" /> 
                                                <h:panelGroup>
                                                    <h:outputText id="cashInAdvance" value="#{InvoiceManagedBean.selectedViewInvoice.cashInAdvance}" />
                                                </h:panelGroup>

                                                <h:outputText value="Products Ordered" /> 
                                                <h:outputText value=":" /> 

                                                <p:dataTable id="childPanel" value="#{InvoiceManagedBean.selectedViewProductList}"
                                                             var="lineEntry" style="width:400px;font-size: 12px" >
                                                    <p:column headerText="Item ID">
                                                        <h:outputText value ="#{lineEntry.itemId}"/>
                                                    </p:column>

                                                    <p:column headerText="Item Name">
                                                        <h:outputText value="#{lineEntry.itemName}"/>
                                                    </p:column>

                                                    <p:column headerText="Unit Price">
                                                        <h:outputText value="#{lineEntry.listPrice}"/>
                                                    </p:column>

                                                    <p:column headerText="Quantity">
                                                        <h:outputText value="#{lineEntry.itemQuantity}"/>
                                                    </p:column>
                                                </p:dataTable>

                                                <p:outputPanel rendered="#{InvoiceManagedBean.editMode}" layout="block" style="text-align:right">  
                                                    <p:commandButton value="Save" ajax="true" update="formMain:panel" immediate="false" actionListener="#{InvoiceManagedBean.doSave}"   
                                                                     image="ui-icon ui-icon-disk" />  
                                                    <p:commandButton value="Cancel" onclick="editDialog.hide()" type="button" image="ui-icon ui-icon-close"/>  
                                                </p:outputPanel>

                                            </h:panelGrid>  
                                            <!--  </p:outputPanel>-->

                                        </center>
                                    </p:dialog>  


                                </td>
                            </tr>
                        </table>
                    </div>

                    <div id="top" class="top">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>

                </h:body>
            </f:view>
        </f:view>
    </h:form>
</html>

